<template>
 <!-- 技术-专家委员会-技术服务支持 -->
    <base-breadcrumb>
        <searchData :search-data="searchArr" @search="search"/>
        <a-card>
          <list-table
            ref="table"
            class="export-table"
            :columns="columns"
            :request="loadData"
            :startIndex="0"
            :export-config="{ use: true, select: '技术服务支持', all: '技术服务支持',customColumns: customColumns}"
            :export-permission="{select: 'tm_014_exp_06',all: 'tm_014_exp_06'}">  
            <template slot="prefix">
              <a-button type="primary" @click="handleManage(2)"  v-btnPermission="'tm_014_add_01'">新增</a-button>
            </template>            
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            <span slot="timeArr"  slot-scope="record">{{record.needStartTime}}~{{record.needEndTime}}</span>
            <!-- <template slot="technicalServerType" slot-scope="text, record">
                 {{getTechnicalServerName(record.technicalServerType)}}
            </template> -->
            <!-- 操作 -->
              <template slot="action" slot-scope="text, record">
                  <MoreButton>
                    <a v-if="record.statusInfo ==='未提交' || record.statusInfo ==='待开始'"  @click="handleManage(0, record)" v-btnPermission="'tm_014_loo_04'">查看</a>
                    <template v-if="record.statusInfo ==='进行中' || record.statusInfo ==='已完结' " v-btnPermission="'tm_014_edi_02'">
                        <a @click="handleManage(0, record)">查看会议</a>
                        </template>
                    <template v-btnPermission="'tm_014_edi_02'" v-if="(record.statusInfo==='未提交' ||record.statusInfo==='待开始')&&hideBuquBtn()">
                        <a @click="handleManage(1, record)">编辑</a>
                        </template>
                        <template v-btnPermission="'tm_014_del_03'"  v-if="record.statusInfo!=='进行中'&&hideBuquBtn()">
                        <a @click="handleRemoveParams(record)">删除</a>
                    </template>
                  </MoreButton>
                </template>
          </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import {delSupport,getSupportList} from '@/api/technical/serviceSupport'
import {technicalServiceType,typeListApproval} from './model'
import { sysNoticeDeleteByBusinessId } from '@/api/commons.js'
import { getAllBranchCompany } from '@/api/commons'
const columns = [
    { title: '所属组织机构',width: '200px',dataIndex: 'supportOrgName',ellipsis: true},
    {title: '所属项目',width: '200px',dataIndex: 'projectName',ellipsis: true},
    {title: '技术服务名称',width: '200px',dataIndex: 'technicalServerName',ellipsis: true},
    {title: '技术服务类型',width: '120px',dataIndex: 'technicalServerType',ellipsis: true,},
    {title: '主持人',width: '120px',dataIndex: 'meetingHost',ellipsis: true},
    {title: '召开时间',width: '240px',ellipsis: true,dataIndex:'holdTime' },
    {title: '状态',width: '120px',dataIndex: 'statusInfo',scopedSlots: { customRender: 'status' },ellipsis: true},
    {title: '操作',dataIndex: 'action',fixed: 'right',width: '180px',scopedSlots: { customRender: 'action' },},
]
export default {
    name:'a'+Date.now(),
    components: {
        SelectSubCompany,
        SelectProject,
    },
    data() {
        this.columns = columns
        this.customColumns = columns.slice(0,7)
        return {
            loadData: (parameter) => {
              let that = this
            //   parameter.pageNum = parameter.pageNo;
            //   delete parameter.pageNo;
              const requestParameters = Object.assign({}, parameter, { query: that.queryParam })
              return getSupportList(requestParameters).then((res) => {
                return res
              })
            },
            loading: {
                isTable: false,
                subChangeCycle: false
            },
            queryParam: {},
            companyList:[]
        }
    },
    computed:{
      searchArr() {
        return [
         // 搜索框
         {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
          // {
          //   name: '所属组织机构',
          //   value: 'branchComId',
          //   placeholder: '请选择',
          //   type: 'select',
          //   // request: this.querCompany,
          //   data: this.companyList
          // },
      //  {name: '所属项目',placeholder: '请选择',valueKey: 'projectId',keyValue: 'branchComId',type: SelectProject,isSelf:false,},
       {name: '技术服务名称',value: 'technicalServerName',type: 'input',},
       {name: '技术服务类型',value: 'technicalServerTypeId',type: 'select',data: technicalServiceType},
       {name: '主持人',value: 'meetingHost',type: 'input',},
       {name: '召开时间',type: 'dateRange',value: 'submitTime',
        attr: {
            rangeFormat: ['fillingInTimeBegin', 'fillingInTimeEnd']
        }
      },
      {name: '状态',value: 'status',type: 'select',data: typeListApproval,}
        ]
      }
    },
    created() {
      this.querCompany()
    },
    methods: {
    getTechnicalServerName(str){
      let name = '';
       if(str){
           name = str*1===0?'业务管控服务':'项目技术服务';
       }
       return name;
    },    
    querCompany() {
        return getAllBranchCompany({tagCodes: ['BC']}).then((res) => {
        let co = [{
            id: "53085e2c9f1f4685801ef31994f57c49",
            name: "总部机关",
        }]
        res.data = [ ...co, ...res.data ];
        let datas = res.data.map((item, index) => {
          return { label: item.name, value: item.id }
        })
        this.companyList = datas
        })
    },
       // 删除数据
     async handleRemoveParams(e) {
            let that = this
            that.$confirm({
                title: '温馨提示',
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                async onOk() {
                    let dataOne = await delSupport({ id: e.id });
                    if(dataOne.data.code == 200){
                       that.$message.success('删除成功！');
                          that.$refs.table.refresh()
                    }else{
                        that.$message.warning(dataOne.message)
                    }
                    if(e.statusInfo!='未提交'){
                       let dataTwo = await sysNoticeDeleteByBusinessId({ id: e.id });
                       if(dataTwo.code==0){
                         that.$refs.table.refresh()
                      }
                    }

                },
            })
        },
        search(values) {
          this.queryParam = { ...values }
          this.$refs.table.refresh()
        },
        detailed(record, type) {
            this.$router.push({
                path: '/technical/ShiGroup/newPlan',
                query: {
                    type,
                    id: record.id,
                },
            })
        },
         // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type,

            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateServiceSupport',
                query
            })
                //  this.$router.push({
                //     name: 'safetyEducationInputSummary',
                //     query: {
                //         id: data.id || '',
                //         pageType: type,
                //         printType: 'education'
                //     },
                // })
        }
    },
}
</script>

<style lang="less">
</style>
